<?php
namespace Home\Controller;

use Think\Controller;
use Home\Model\UserModel;

class IndexController extends Controller
{
	public function index(){
		$this->display();
	}

	public function login(){

        $username = addslashes(strip_tags(trim(I('post.username'))));
        $password = sha1(addslashes(strip_tags(trim(I('post.password')))));

        if(!empty($_POST)){
            
            $user = new UserModel();
            $rst  = $user->checkNamePwd($username, $password);

            if ($rst != false ) {
                        
                session_start();
                session('username', $username);
                
                $this->redirect('Admin/index', 0);

            } else{

                $this->redirect('Index/index', array('x' => 2), 0);
            }
        }
    }   
} 